# Find the Bristol Tracking Library
# uses $ENV{BTL} as a hint to help find the library

if (DEFINED BTLGUI_FOUND)
   if (BTLGUI_FIND_REQUIRED AND (NOT BTLGUI_FOUND))
      message(SEND_ERROR "Could not find BTLGUI")
   endif()
   return()
endif()

find_package(BTL REQUIRED)

set(BTLGUI_ROOT "$ENV{BTL_GUI}" CACHE PATH "The root for BTL GUI libraries.")

# set up build environment
set(BTLGUI_INCLUDE_DIRS
   ${BTLGUI_ROOT}/include/Qt/VideoSourceGui/src
   ${BTLGUI_ROOT}/include/Qt/OgreGraphicsGui/src
   ${BTLGUI_ROOT}/include/Qt/VisualSlamSystemGui/src
   ${BTLGUI_ROOT}/include/Qt/OgreVisualSlamSystemGui/src
)

set(X_BTLGUI_LIBRARIES
   ${BTLGUI_ROOT}/Qt/VideoSourceGui/BtlQtVideoSource
   ${BTLGUI_ROOT}/Qt/OgreGraphicsGui/BtlQtOgreGraphics
   ${BTLGUI_ROOT}/Qt/VisualSlamSystemGui/BtlQtVisualSlamSystem
   ${BTLGUI_ROOT}/Qt/OgreVisualSlamSystemGui/BtlQtOgreVisualSlamSystem
)

set(MISSING_BTLGUI_LIBS)
set(BTLGUI_LIBRARIES)

set(BTLGUI_FOUND TRUE)

foreach(X_BTLGUI_LIB ${X_BTLGUI_LIBRARIES})
	get_filename_component(X_BTLGUI_LIB_PATH "${X_BTLGUI_LIB}" PATH)
	get_filename_component(X_BTLGUI_LIB_NAME "${X_BTLGUI_LIB}" NAME)

	find_library(BTLGUI_${X_BTLGUI_LIB_NAME}_LIBRARY
		NAMES "${X_BTLGUI_LIB_NAME}"
		PATHS "${BTLGUI_ROOT}" "${X_BTLGUI_LIB_PATH}"
		PATH_SUFFIXES lib
		DOC "BTLGUI ${X_BTLGUI_LIB_NAME} library"
		NO_DEFAULT_PATH
	)

	if (NOT (BTLGUI_${X_BTLGUI_LIB_NAME}_LIBRARY))
		set(BTLGUI_FOUND FALSE)
		list(APPEND MISSING_BTLGUI_LIBS ${X_BTLGUI_LIB_NAME})
	else()
		list(APPEND BTLGUI_LIBRARIES ${BTLGUI_${X_BTLGUI_LIB_NAME}_LIBRARY})
	endif()
endforeach()

if (BTLGUI_FOUND)
	message(STATUS "Found BTLGUI")
else()
	message(WARNING "BTLGUI not found, missing ${MISSING_BTLGUI_LIBS}")
endif()

unset(MISSING_BTLGUI_LIBS)
